<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="ThemeBucket">
    <link rel="shortcut icon" href="#" type="image/png">

    <title>Form Layouts</title>
    <!--file upload-->
    <link rel="stylesheet" type="text/css" href="/public/css/bootstrap-fileupload.min.css" />

    <link href="/public/js/iCheck/skins/flat/green.css" rel="stylesheet">

    <?php $this->load->view('library/header');?>
</head>

<body class="sticky-header">

<section>
    <?php $this->load->view('library/left');?>

    <!-- main content start-->
    <div class="main-content" >

        <?php $this->load->view('library/top');?>

        <!-- page heading start-->
        <div class="page-heading">
            <h3>
                产品补充
            </h3>
            <ul class="breadcrumb">
                <li>
                    <a href="#">Forms</a>
                </li>
                <li class="active"> Forms Layouts </li>
            </ul>
        </div>
        <!-- page heading end-->

        <!--body wrapper start-->
        <section class="wrapper">
            <!-- page start-->

            <div class="row">
                <div class="col-lg-12">

                    <section class="panel">
                        <div class="panel-body">
                            <form class="cmxform form-horizontal adminex-form" id="commentForm" enctype="multipart/form-data" method="post" action="">
                                <div class="form-group">
                                    <label for="cemail" class="control-label col-lg-2">货号</label>
                                    <div class="col-lg-3">
                                        <h5><?php echo $prepare['goods_sn'];?></h5>
                                        <div style="width: 80px; margin: 0;" class="thumbnail">
                                        <img src="<?php echo $prepare['original_img'];?>" />
                                        </div>
                                    </div>
                                </div>


                                <div class="form-group addsupp">
                                    <label for="curl" class="control-label col-lg-2">1688链接</label>
                                    <div class="col-lg-3">
                                        <input class="form-control curl" type="text" value="" name="supp_url" />
                                    </div>
                                    <div class="col-lg-2">
                                        <input class="form-control supp_sn" value="" type="text" name="supp_sn" placeholder="货号">
                                        <input type="hidden" class="g_supp_id" name="g_supp_id" value="" />
                                    </div>
                                    <div class="col-lg-2">
                                        <div class="input-group">
                                            <span class="input-group-addon">￥</span>
                                            <input type="text" value="" name="in_price" class="form-control in_price" placeholder="进货价">
                                        </div>
                                    </div>
                                    <div class="col-lg-1">
                                        <a class="get-goods" href="javascript:;">获取信息</a>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="curl" class="control-label col-lg-2">1688商品名称</label>
                                    <div class="col-lg-6">
                                        <input class="form-control supp_name" type="text" value="" name="supp_name" />
                                    </div>
                                </div>
                                <div class="form-group ">
                                    <label for="curl" class="control-label col-lg-2">价格</label>
                                    <div class="col-lg-2">
                                        <div class="input-group">
                                            <span class="input-group-addon">$</span>
                                            <input type="text" value="" name="shop_price" class="form-control" placeholder="售价">
                                        </div>
                                    </div>
                                </div>
                                <div class="form-group supp_sku">
                                    <label class="control-label col-lg-2">尺码颜色信息</label>
                                    <div class="col-lg-10 icheck" >
                                        <div class="col-lg-7 sku_color">

                                        </div>
                                        <div class="col-lg-5 sku_size">

                                        </div>
                                    </div>
                                </div>

                                
                                <div class="form-group">
                                    <label class="col-lg-2 col-sm-2 control-label"></label>
                                    <div class="col-lg-10">

                                        <button type="submit" class="btn btn-primary">提交</button>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </section>
                </div>
            </div>
            <!-- page end-->
        </section>
        <!--body wrapper end-->

        <!--footer section start-->
        <footer>
            2014 &copy; AdminEx by
        </footer>
        <!--footer section end-->


    </div>
    <!-- main content end-->
</section>

<?php $this->load->view('library/footer');?>

<!--icheck -->
<script src="/public/js/iCheck/jquery.icheck.js"></script>
<script src="/public/js/icheck-init.js"></script>

<script src="/public/js/express-art-template-master/template-web.js"></script>
<script type="text/html" id="color_temp">
    <% for(var i = 0; i < items.length; i++){ %>
    <div class="row" style="margin-top: 15px; margin-left: -30px;">
        <div class="col-lg-6">
            <img width="35" src="<%=items[i].imageUrl%>" class="img-rounded" style="float: left; margin-right: 15px;" />
            <input style="float: left; width: 200px;" value="<%=items[i].name%>" name="aliyun_sku[ali_color][]" readonly = "readonly" class="form-control sunjian_ali_color">
        </div>
        <div class="col-lg-5">
            <select name="aliyun_sku[color][]" class="option-color form-control sunjian_color supp_sku_color">
                <option value="">选择颜色</option>
                <?php foreach ($color_option as $k => $color) :?>
                    <option value="<?php echo $k;?>"><?php echo $color;?></option>
                <?php endforeach;?>
            </select>
        </div>
    </div>
    <% } %>
</script>
<script type="text/html" id="size_temp">
    <% for(var i = 0; i < items.length; i++){ %>
    <div class="row" style="margin-top: 15px;">
        <div class="col-lg-4">
            <input value="<%=items[i].name%>" name="aliyun_sku[ali_size][]" readonly = "readonly" class="form-control sunjian_ali_size">
        </div>
        <div class="col-lg-6">
            <select name="aliyun_sku[size][]" class="option-size form-control sunjian_size supp_sku_size">

                <option value="">选择尺码</option>
                <?php foreach ($size_option as $size) :?>
                    <option value="<?php echo $size;?>"><?php echo $size;?></option>
                <?php endforeach;?>
            </select>
        </div>
    </div>
    <% } %>
</script>
<!--file upload-->
<script type="text/javascript" src="/public/js/bootstrap-fileupload.min.js"></script>
<script type="text/javascript">

    $(function () {


        $('#commentForm').submit(function () {
            $('button[type="submit"]').attr('disabled','disabled').addClass('btn-submit-disabled').html('正在提交，请稍等...');

            var data = new FormData(this);

            $.ajax({
                url: '<?php echo base_url("PrepareGoods/set/prepare_id/{$prepare['prepare_id']}/step/2");?>',
                type: 'POST',
                cache: false,
                dataType:'json',
                data: data,
                success: function(data) {
                    if (data.status != 'success') {
                        swal({
                            title:   data.info,
                            text: '2秒后关闭',
                            type: data.status,
                            allowOutsideClick: false,
                            timer: 1500,
                            showConfirmButton: false
                        });
                    } else {
                        swal({
                            title: data.info,
                            text: '2秒后关闭',
                            type: data.status,
                            allowOutsideClick: false,
                            timer: 1500,
                            showConfirmButton: false
                        }).then(function(isConfirm) {
                            window.onbeforeunload = '';
                            window.location.href = '<?php echo base_url('PrepareGoods/index_accurate?prepare_state=2');?>';
                        });
                    }
                    $('button[type="submit"]').attr("disabled",false).removeClass('btn-submit-disabled').html('提交信息');
                },
                processData: false,
                contentType: false
            });
            setTimeout(function() {
                $('button[type="submit"]').attr("disabled",false).removeClass('btn-submit-disabled').html('提交信息');
            }, '3000');
            return false;
        });

        $('.get-goods').on('click', function () {

            var supp = $(this).parents('.addsupp').find('.curl').val();

            thisg = $(this);

            $(this).html('获取中...');
            var supp_id = $('.selectpicker').val();
            $.post("<?php echo base_url('PrepareGoods/ajax_ali_goods');?>", {ali_url: supp,supp_id:supp_id}, function (aliData) {

                var result_color = '', result_size = '';
                var data = aliData.data;

                thisg.parents('.addsupp').find('.supp_sn').val(data.ali_sn);
                thisg.parents('.addsupp').find('.in_price').val(data.ali_price);
                thisg.parents('.addsupp').find('.g_supp_id').val(data.g_supp_id);

                $('.supp_name').val(data.title);

                if (data.skuProps) {
                    for (var x in data.skuProps) {

                        var obj = {
                            items: data.skuProps[x].value
                        };

                        if (data.skuProps[x].prop === '颜色') {
                            result_color += template('color_temp', obj);
                        } else if (data.skuProps[x].prop === '尺码') {
                            result_size += template('size_temp', obj);
                        }
                    }
                    $('.supp_sku .sku_color').html(result_color);
                    $('.supp_sku .sku_size').html(result_size);
                    $('.flat-green input').iCheck({
                        checkboxClass: 'icheckbox_flat-green',
                        radioClass: 'iradio_flat-green'
                    });
                }


            }, 'json');
        });


        //获取货号
        $('#admin_id').change(function () {

            $.post('<?php echo base_url('PrepareGoods/get_goods_sn');?>',{admin_id:$(this).val()},function (goods_sn) {
                $('#goods_sn').val(goods_sn);
            }, 'text');
        });

    });

</script>

<!--common scripts for all pages-->
<script src="/public/js/scripts.js"></script>

</body>
</html>
